package com.zking.controller;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;
import com.zking.config.AlipayConfig;
import com.zking.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@RequestMapping("products")
public class ProductController {

    @Autowired
    ProductService ps;

    @RequestMapping("find/{id}")
    public String findById(HttpSession session, @PathVariable Integer id){
        session.setAttribute("productid",id);
        return "redirect:/shangp_xiangq.jsp";
    }

    @RequestMapping("init")
    @ResponseBody
    public Map<String,Object> init(HttpSession session){
        Integer spid = (Integer) session.getAttribute("productid");
        return ps.initProduct(spid);
    }

    // 购买成功后进入 需要在这里修改订单状态为已付款
    @RequestMapping("paysuccess")
    public String a(String out_trade_no,String total_amount){
        System.out.println("付款的订单id:"+out_trade_no);
        System.out.println("总价格:"+total_amount);
        return "index";
    }
}
